package bar.dark.lee.setting.sms;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import bar.dark.lee.BDConstents;
import bar.dark.lee.R;
import bar.dark.lee.SuperActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.DBSQLite;

public class SmsNotiSettingActivity extends SuperActivity
{
	private DBSQLite sql;
	
	private View okView;
	private View noView;
	
	private RadioButton okCheckBox;
	private RadioButton noCheckBox;
	
	private Button saveButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		sql = DBSQLite.getInstance(superContext);
		
		setContentView(R.layout.setting_sms_noti_activity);
		
		setTitle("상단바 알림표시 설정");
		
		setGoneTipButton();
		
		setFindView();
		setOnClickListener();
		setData();
	}

	private void setFindView()
	{
		okView = findViewById(R.id.settingSmsNotiOkView);
		noView = findViewById(R.id.settingSmsNotiNoView);
		
		okCheckBox = (RadioButton) findViewById(R.id.settingSmsNotiOkCheckBox);
		noCheckBox = (RadioButton) findViewById(R.id.settingSmsNotiNoCheckBox);
		
		saveButton = (Button) findViewById(R.id.settingSmsNotiSaveButton);
	}
	
	private void setOnClickListener()
	{
		okView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				okCheckBox.setChecked(true);
				noCheckBox.setChecked(false);
			}
		});
		
		noView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				okCheckBox.setChecked(false);
				noCheckBox.setChecked(true);
			}
		});
		
		saveButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
				SharedPreferences.Editor editor = pref.edit();
				
				if (okCheckBox.isChecked())
				{
					editor.putInt(BDConstents.SMS_NOTI_SETTING, 0);
				}
				else
				{
					editor.putInt(BDConstents.SMS_NOTI_SETTING, 1);
				}
				
				editor.commit();
				
				BDUtil.showDialogFinish(superContext, "알림", "상단바 알림 설정이 저장 되었습니다.");
			}
		});
	}
	
	private void setData()
	{
		SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
		int checkFlag = pref.getInt(BDConstents.SMS_NOTI_SETTING, 0);
		
		if (checkFlag == 0)
		{
			okCheckBox.setChecked(true);
			noCheckBox.setChecked(false);
		}
		else if (checkFlag == 1)
		{
			okCheckBox.setChecked(false);
			noCheckBox.setChecked(true);
		}
	}

	@Override
	protected void tipButton()
	{
	}

}
